package com.slm.report.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.blankj.utilcode.util.TimeUtils;
import com.slm.report.databinding.AdapterDuShuItemBinding;
import com.slm.report.db.DuShuInfoBean;

import java.util.List;

/**
 * @ProjectName: My Application
 * @Package: com.slm.report.adapter
 * @ClassName: DuShuListAdapter
 * @Description: java类作用描述
 * @Author: 王丹丹
 * @CreateDate: 2020/6/3 22:08
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/6/3 22:08
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class DuShuListAdapter extends BaseAdapter {
    private Context mContext;
    private OnDelDataCallBack onDelDataCallBack;
    private List<DuShuInfoBean> infoBeanList;

    public interface OnDelDataCallBack {
        void deleteData(DuShuInfoBean infoBean);
    }


    public DuShuListAdapter(Context mContext, List<DuShuInfoBean> infoBeanList,OnDelDataCallBack onDelDataCallBack) {
        this.mContext = mContext;
        this.infoBeanList = infoBeanList;
        this.onDelDataCallBack=onDelDataCallBack;
    }

    @Override
    public int getCount() {
        return infoBeanList == null ? 0 : infoBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return infoBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AdapterDuShuItemBinding adapterDuShuItemBinding = null;
        if (convertView == null) {
            adapterDuShuItemBinding = AdapterDuShuItemBinding.inflate(LayoutInflater.from(mContext));
            convertView = adapterDuShuItemBinding.getRoot();
            convertView.setTag(adapterDuShuItemBinding);
        } else {
            adapterDuShuItemBinding = (AdapterDuShuItemBinding) convertView.getTag();
        }
        final DuShuInfoBean duShuInfoBean = (DuShuInfoBean) getItem(position);
        adapterDuShuItemBinding.lSphTv.setText(duShuInfoBean.getLeftSph());
        adapterDuShuItemBinding.lAxTv.setText(duShuInfoBean.getLeftAx());
        adapterDuShuItemBinding.lCylTv.setText(duShuInfoBean.getLeftCyl());
        adapterDuShuItemBinding.rSphTv.setText(duShuInfoBean.getRightSph());
        adapterDuShuItemBinding.rAxTv.setText(duShuInfoBean.getRightAx());
        adapterDuShuItemBinding.rCylTv.setText(duShuInfoBean.getRightCyl());
        adapterDuShuItemBinding.timeTv.setText(TimeUtils.millis2String(duShuInfoBean.getCreateTime()));

        adapterDuShuItemBinding.delTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDelDataCallBack != null) {
                    onDelDataCallBack.deleteData(duShuInfoBean);
                }
            }
        });
        return convertView;
    }
}

